package com.kkb.springcloudbill.client.controller;

import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@Controller
@Slf4j
public class controller {
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/")
    public ResponseEntity<PageInfo<Bill>> initPage(
            @RequestBody Bill bill,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize){
            ResponseEntity responseEntity = restTemplate.getForObject("http://127.0.0.1:8091/bill", ResponseEntity.class, bill, pageNum, pageSize);
            return responseEntity;
        }

    @RequestMapping("/test")
    public String test(){
        System.out.println("---------------------------------------------------------");
//        return "client test finished";
        return restTemplate.getForObject("http://127.0.0.1:8091/test", String.class);
    }
}
